package model.commands.misc;

import java.util.Map;
import model.Environment;
import model.SyntaxErrorException;
import model.commands.Command;


/**
 * Name:
 * :x
 * 
 * Description:
 * Returns the value of :x
 * 
 * @author JLongley
 * @author Erick Gonzalez
 */
public class VariableCommand extends Command  {
    private Map<String, Integer> myVariables;
    private String myVarName;    

    /**
     * 
     * @param variables a mapping from variable names to variables values
     * @param varName a variable name
     */
    public VariableCommand(Map<String, Integer> variables, String varName) {
        myVariables = variables;
        myVarName = varName;        
    }

    @Override
    public int evaluate(Environment e) throws SyntaxErrorException {               
        //if variable not defined
        if (!myVariables.containsKey(myVarName)) {
            throw new SyntaxErrorException("Unknown variable!");
        }
        
        return myVariables.get(myVarName);
    }
}
